﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DingHeng.TransportationManagement.Business;
using DingHeng.TransportationManagement.Entity;
using DingHeng.TransportationManagement.WebCommon.BaseUI;

namespace DingHeng.TransportationManagement.WebSite.Biz
{
    public partial class VehicleDispatchFormList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.CutPageControl.PageSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("pageSize"));
                lblHomeTitle.Text = "查询派车单";
                this.CutPageControl.PageSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("pageSize"));
                this.gridVehicelDispatchList.DataSource = new List<VehicleDispatchFormInfo>();
                this.gridVehicelDispatchList.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.CutPageControl.PageIndex = 1;
            dataBind();
        }

        private void dataBind()
        {
            VehicleDispatchFormCriteria criteria = new VehicleDispatchFormCriteria();

            criteria.Code = null;
            DateTime dt = DateTime.Now;
            if (!string.IsNullOrEmpty(this.txtVehicleDispatchDateEnd.Text)
                && DateTime.TryParse(this.txtVehicleDispatchDateEnd.Text, out dt))
            {
                criteria.DispatchTimeEnd = dt.AddDays(1).AddSeconds(-1);
            }
            if (!string.IsNullOrEmpty(this.txtVehicleDispatchDateStart.Text)
                && DateTime.TryParse(this.txtVehicleDispatchDateStart.Text, out dt))
            {
                criteria.DispatchTimeStart = dt;
            }

            criteria.ProjectName = null ;
            criteria.VehicleLicensePlateNo = this.txtLicensePlateNo.Text.Trim();
            criteria.VehicleNo = this.txtVehicleNo.Text.Trim();

            Pager<VehicleDispatchFormInfo> pager = new Pager<VehicleDispatchFormInfo>();
            pager.PageSize = this.CutPageControl.PageSize;
            pager.PageIndex = this.CutPageControl.PageIndex;
            List<VehicleDispatchFormInfo> vehicleDispatchFormInfoList = new VehicleDispatchFormBiz().GetPageList(criteria, pager);

            this.gridVehicelDispatchList.DataSource = vehicleDispatchFormInfoList;
            this.gridVehicelDispatchList.DataBind();
            if (pager != null)
            {
                this.CutPageControl.DataCount = pager.TotalCount;
                //Log.LogInfo("分页数据加载成功");
            }
            else
            {
                this.CutPageControl.DataCount = vehicleDispatchFormInfoList.Count();
                //Log.LogInfo("分页数据为空，加载本页分页最大记录数");
            }
            this.CutPageControl.PageBind();
        }


        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void CutPageControl_PageSelected(object sender, EventArgs e)
        {
            dataBind();
        }
    }
}